import 'package:equatable/equatable.dart';
import 'package:website.core/core/domain/entities/web/web_subscription_duration.dart';

const kApiWebSubscriptionMonthDurationValue = 'month';
const kApiWebSubscriptionYearDurationValue = 'year';

class ApiWebSubscriptionDurationDto extends Equatable {
  const ApiWebSubscriptionDurationDto._internal({
    required this.durationString,
  });

  final String durationString;

  @override
  List<Object?> get props {
    return [
      durationString,
    ];
  }

  factory ApiWebSubscriptionDurationDto.fromString(String durationString) {
    return ApiWebSubscriptionDurationDto._internal(
      durationString: durationString,
    );
  }

  WebSubscriptionDuration toEntity() {
    if (durationString == kApiWebSubscriptionMonthDurationValue) {
      return WebSubscriptionDuration.month;
    }

    if (durationString == kApiWebSubscriptionYearDurationValue) {
      return WebSubscriptionDuration.year;
    }

    throw UnimplementedError();
  }
}
